unit clsinstala;

interface

uses Dm,dbtables,biblio, SysUtils;

type
  TInstala=Class(TObject)
    private
      inst_codigo    : String; //      VARCHAR(1) NOT NULL,
    public
      Inst_Razao     : String; //      VARCHAR2(50) NULL,
      Inst_Fantasia  : String; //      VARCHAR2(30) NULL,
      Inst_Endereco  : String; //      VARCHAR2(50) NULL,
      Inst_Bairro    : String; //      VARCHAR2(30) NULL,
      Inst_Cidade    : String; //      VARCHAR2(25) NULL,
      Inst_Cep       : String; //      VARCHAR2(9) NULL,
      Inst_UF        : String; //      VARCHAR2(2) NULL,
      Inst_CGC       : String; //      VARCHAR2(18) NULL,
      Inst_Inscricao : String; //      VARCHAR2(20) NULL,
      Inst_Fone      : String; //      VARCHAR2(14) NULL,
      Inst_Fax       : String; //      VARCHAR2(14) NULL,
      Inst_Banco     : String; //      VARCHAR2(15) NULL
      function  Gravar(p_Inst_codigo:String):Byte;
      function  Recuperar(p_Inst_codigo:String):Byte;
  end;

implementation


function TInstala.Gravar;
var tq:TQuery;
begin
 tq             := Tquery.Create(DmInt);
 tq.databasename:= dmint.Db.DatabaseName;
 tq.active      := False;
 tq.sql.clear;
 tq.params.clear;
 tq.sql.add('SELECT * FROM Instala where Inst_Codigo=:k_Inst_Codigo');
 tq.parambyname('k_Inst_Codigo').asstring:= p_inst_codigo;
 tq.open;
 if tq.eof then begin
   tq.sql.clear; tq.params.clear;
   tq.sql.add('INSERT INTO Instala VALUES('+
      ':k_Inst_Codigo,'+
      ':k_Inst_Razao,'+
      ':k_Inst_Fantasia,'+
      ':k_Inst_Endereco,'+
      ':k_Inst_Bairro,'+
      ':k_Inst_Cidade,'+
      ':k_Inst_Cep,'+
      ':k_Inst_UF,'+
      ':k_Inst_CGC,'+
      ':k_Inst_Inscricao,'+
      ':k_Inst_Fone,'+
      ':k_Inst_Fax,'+
      ':k_Inst_Banco)');
 end;
 tq.parambyname('k_Inst_Codigo').asstring    := '1';
 tq.parambyname('k_Inst_Razao').asstring     := Inst_Razao;
 tq.parambyname('k_Inst_Fantasia').asstring  := Inst_Fantasia;
 tq.parambyname('k_Inst_Endereco').asstring  := Inst_Endereco;
 tq.parambyname('k_Inst_Bairro').asstring    := Inst_Bairro;
 tq.parambyname('k_Inst_Cidade').asstring    := Inst_Cidade;
 tq.parambyname('k_Inst_Cep').asstring       := Inst_Cep;
 tq.parambyname('k_Inst_UF').asstring        := Inst_UF;
 tq.parambyname('k_Inst_CGC').asstring       := Inst_CGC;
 tq.parambyname('k_Inst_Inscricao').asstring := Inst_Inscricao;
 tq.parambyname('k_Inst_Fone').asstring      := Inst_Fone;
 tq.parambyname('k_Inst_Fax').asstring       := Inst_Fax;
 tq.parambyname('k_Inst_Banco').asstring     := Inst_Banco;
 tq.close;
 tq.execsql;
 result:= 1;
 tq.close;
 tq.Free;
end;

function TInstala.Recuperar;
var tq: TQuery;
begin
 tq             := Tquery.Create(dmint);
 tq.databasename:= DmInt.Db.DatabaseName;
 tq.active      := False;
 tq.sql.clear;
 tq.sql.add('SELECT * FROM Instala where Inst_Codigo=:k_Inst_Codigo');
 tq.parambyname('k_Inst_Codigo').asstring:= p_inst_codigo;
 tq.open;
 Inst_Codigo       := p_Inst_Codigo;
 if tq.eof then Result:= 0 else Result:= 1;
 Inst_Razao     := tq.fieldbyname('Inst_Razao').asstring;
 Inst_Fantasia  := tq.fieldbyname('Inst_Fantasia').asstring;
 Inst_Endereco  := tq.fieldbyname('Inst_Endereco').asstring;
 Inst_Bairro    := tq.fieldbyname('Inst_Bairro').asstring;
 Inst_Cidade    := tq.fieldbyname('Inst_Cidade').asstring;
 Inst_Cep       := tq.fieldbyname('Inst_Cep').asstring;
 Inst_UF        := tq.fieldbyname('Inst_Uf').asstring;
 Inst_CGC       := tq.fieldbyname('Inst_CGC').asstring;
 Inst_Inscricao := tq.fieldbyname('Inst_Inscricao').asstring;
 Inst_Fone      := tq.fieldbyname('Inst_Fone').asstring;
 Inst_Fax       := tq.fieldbyname('Inst_Fax').asstring;
 Inst_Banco     := tq.fieldbyname('Inst_Banco').asstring;
 tq.Close;
 tq.Free;
end;

end.

